package com.ruoyi.yl.common;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.gislife.a4.modules.business.dto.base.BasePageResVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2022/2/18 0:12
 * @FileName: Result
 * @version: 1.0
 * @Description: 封装向前端返回的信息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties("handler")
public class Result<T> implements Serializable {

    /**
     * 响应状态码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 返回的数据
     */
    private T data;

    public Result(T data) {
        this.data = data;
    }

    public static Result<String> success() {
        Result<String> result = new Result<>();
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }
    public Result<com.gislife.a4.modules.business.dto.base.BasePageResVO<T>> ok(List<T> list) {
        Result<com.gislife.a4.modules.business.dto.base.BasePageResVO<T>> result = new Result<>();
        com.gislife.a4.modules.business.dto.base.BasePageResVO<T> basePageResVO = new BasePageResVO<>();
        basePageResVO.setData(list);
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data);
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }

    public static Result<String> error(Integer code, String message) {
        Result<String> result = new Result<String>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    
    /**
     * 没有返回数据时的构造器
     *
     * @param code    状态码
     * @param message 返回信息
     */
    public Result(Integer code, String message) {

        this.code = code;
        this.message = message;
        this.data = null;
    }
}